import { reminds, replaceStr } from '@/utils/notification'
export default{
  methods: {
    replaceStr(str, arr) {
      const regArr = str.match(/\-\d\-/g)
      let temp = str
      if (regArr) {
        for (let i = 0; i < regArr.length; i++) {
          temp = temp.replace(new RegExp(regArr[i], 'g'), arr[i])
        }
        return temp
      } else {
        return str
      }
    },
    netTips(res, ...arg) {
      if (res.code === 1) {
        arg.forEach(fn => {
          if (typeof fn === 'function') {
            fn()
          }
        })
        this.$notify({
          message: replaceStr(this.$t(String(res.message)), res.data),
          type: reminds[res.code],
          duration: 3500
        })
      } else {
        this.$notify({
          message: replaceStr(this.$t(String(res.message)), res.data),
          type: reminds[res.code],
          duration: 0
        })
      }
    },
    // 简单的el-date-picker值的处理
    handleTime(start, end, time) {
      if (time) {
        return {
          [start]: time[0],
          [end]: time[1]
        }
      } else {
        return {
          [start]: null,
          [end]: null
        }
      }
    }
  }
}
